// var arr = []; arr.push('123') arr.push(12) 
const arr:string[] = ['12']

// 接口 : interface  
// 接口可以定义 引用数据类型 
interface Person{
  // username : 键
  username : string;
  sex?:number;
  readonly age:number;
}

let obj1 : Person = {
  username:'',
  age:123
}

// 写 
// obj1.age = 1
console.log(obj1.age)

// number  string  
// 可选 ?
const arr1:Array<Person> = [{username:'123',sex:123,age:123},{username:'123',age:123}]


// arr.push(1)

/**
 * [
 *  {
 *    username:'',
 *    age:[1,2,3,4],
 *    friends:[
 *      {
 *        username:'',
 *        nickName:''
 *      }
 *    ]
 *  }
 * ]
 */

interface Friends{
  username:string,
  nickName:string
}
interface Person1{
  username:string,
  age:Array<number>,
  friends:Array<Friends>
}


let arrPerson:Array<Person1>

// arrPerson.push({username:'',age:[1,2,3],friends:[{username:'123',nickName:'123'}]})

// 元组  约束数组的类型 [number , string]

let tulb : [Array<Person>,number] // 元组 [[{}],1]
// 返回数据 [本体,条数]

// enum : 枚举 : 

// 数据类型
enum Colors {
  RED = 'RED', //0
  GREEN = 'GREEN', //1
  BLUE = 'BLUE' //2
}
Colors.GREEN //?

function getColor (color:Colors){
  switch(color){
    case  Colors.BLUE:
      console.log('blue')
    break;
  }
}

getColor(Colors.BLUE)
const arr3 :Array<Colors> = [Colors.BLUE]

arr3.push(Colors.BLUE)

interface Person2{
  colors:Array<Colors>
}

// es5 的类  
// function Paa{}

// es6 
// class Person5{

// }

// ts的类

class Controller{
  // 构造 new Controller()
  // private :私有的
  // public 公开的
  // protected : 只能在当前类以及子类里面调用
  // readonly

  private readonly age = 20;
  // 受保护的
  protected readonly age1 = 20;
  // 开闭原则 

  constructor(public readonly username :string ){
    // this.age = 1234
  }
  // username = '';
  private handle():Colors{
    console.log(this.username)
    return Colors.BLUE
  }
}

class UserController extends Controller {
  params2 = 10;
  // 1. new当前的类 一定会调用父类的构造 通过super
  constructor(params:string,params2?:number){
    super(params)
    if(params2){
      this.params2 = params2
    }
    // this.age1
  }
} 

let  instance = new UserController('',12)
// ?. 如果这个类型存在 就调用 如果不存在 得到的就是undefined
if(instance?.params2){
}


// new Controller('123').handle() // 实例 === this

type A = new(...args:any[])=>any;

function classDecorator<T extends {new(...args:any[]):{}}>(constructor:T) {
  return class extends constructor {
      newProperty = "new property";
      hello = "override";
  }
}

@classDecorator
class Greeter {
  property = "property";
  hello: string;
  constructor(m: string) {
      this.hello = m;
  }
}

console.log(new Greeter("world"));